<template>
  <div class="nav-item" @mouseenter="live2dShowNav">
    <div @click="goPath">
      <pop-tip v-if="showPopTip" class="nav-popTip" :style="{ left: left, top: top }">
        <div style="font-size: 12px">
          {{ ackData.otcDescribe }}
        </div>
      </pop-tip>
      <div class="nav-img" :style="{ backgroundColor: ackData.bgColor }">
        <img :src="ackData.otcPath" alt="" width="50" height="50" />
      </div>
      <div class="nav-name">
        {{ ackData.otcName }}
      </div>
      <div class="nav-desc" @mousemove="pathDesc">
        {{ ackData.otcDescribe }}
      </div>
    </div>
    <div class="nav-path">
      <i
        class="iconfont iconshouye1"
        @click="goNav(ackData.path)"
        v-if="ackData.path"
      ></i>
      <i class="iconfont icongithub" @click="goNav(ackData.name)" v-if="ackData.name"></i>
    </div>
  </div>
</template>

<script setup lang="ts">
import popTip from "@/components/popTipDes.vue";
import Bus from "@/bus";
import { ref } from "vue";
import { ackDataType } from "@/type/navigator";
const props = defineProps({
  ackData: {
    type: Object as () => ackDataType,
    default: () => ({}),
  },
});
const descTime = ref<null | number>(null);
const left = ref<string>("");
const top = ref<string>("");
const showPopTip = ref<boolean>(false);

const pathDesc = (e: MouseEvent) => {
  showPopTip.value = false;
  if (descTime.value) {
    clearTimeout(descTime.value);
  }
  descTime.value = setTimeout(() => {
    showPopTip.value = true;
    left.value = e.offsetX + "px";
    top.value = e.offsetY + 73 + "px";
  }, 1300);
};
const goPath = () => {
  props.ackData.path ? goNav(props.ackData.path) : goNav(props.ackData.name);
};
const live2dShowNav = () => {
  Bus.$emit("live2dAboutNavigation", { title: props.ackData.otcDescribe });
};
const goNav = (path: string) => {
  let a = document.createElement("a");
  a.href = path;
  a.target = "_blank";
  a.click();
};
</script>

<style lang="scss" scoped>
.nav-item {
  width: 150px;
  // height: 200px;
  padding: 5px;
  margin: 15px;
  transition: all 0.2s;
  border-radius: 6px;
  position: relative;
  &:hover {
    z-index: 200;
    box-shadow: 0 0 7px 1px rgba(0, 0, 0, 0.3);
    transform: scale(1.05);
  }
  .nav-popTip {
    position: absolute;
    left: 0;
    z-index: 9;
  }
  .nav-img {
    text-align: center;
  }
  .nav-name {
    font-weight: 200;
    color: #333;
    text-align: center;
  }
  .nav-desc {
    width: 150px;
    height: 51px;
    margin-top: 2px;
    font-size: 12px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    color: rgba(0, 0, 0, 0.4);
    position: relative;
  }
  .nav-path {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    color: rgba(0, 0, 0, 0.4);
    i {
      transition: all 0.3s;
      &:hover {
        color: skyblue;
      }
    }
  }
}
</style>
